home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / workbench / directoryopus4 / dopus4_src / library / menus.c < prev    next >
C/C++ Source or Header  |  2000-03-11  |  5KB  |  170 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "dopuslib.h"
  32.  
  33. __saveds DoFSSetMenuStrip(register struct Window *window __asm("a0"),
  34.     register struct Menu *firstmenu __asm("a1"))
  35. {
  36.     struct Menu *menu;
  37.     struct MenuItem *item;
  38.     struct DrawInfo *drinfo;
  39.     int fpen,bpen;
  40.     int y,offset,xpos=0,iwidth,comwidth,checkwidth;
  41.     struct IntuiText testtext;
  42.     struct TextAttr testattr;
  43.  
  44.     comwidth=COMMWIDTH;
  45.     checkwidth=CHECKWIDTH;
  46.  
  47.     AskFont(&window->WScreen->RastPort,&testattr);
  48.     testtext.FrontPen=1;
  49.     testtext.DrawMode=JAM1;
  50.     testtext.NextText=NULL;
  51.  
  52.     if (IntuitionBase->LibNode.lib_Version>36 &&
  53.         (drinfo=GetScreenDrawInfo(window->WScreen))) {
  54.         if (IntuitionBase->LibNode.lib_Version>=39) {
  55.             fpen=drinfo->dri_Pens[BARDETAILPEN];
  56.             bpen=drinfo->dri_Pens[BARBLOCKPEN];
  57.             if (drinfo->dri_AmigaKey) comwidth=drinfo->dri_AmigaKey->Width;
  58.             if (drinfo->dri_CheckMark) checkwidth=drinfo->dri_CheckMark->Width;
  59.         }
  60.         else {
  61.             fpen=drinfo->dri_Pens[DETAILPEN];
  62.             bpen=drinfo->dri_Pens[BLOCKPEN];
  63.         }
  64.         FreeScreenDrawInfo(window->WScreen,drinfo);
  65.     }
  66.     else {
  67.         fpen=0;
  68.         bpen=1;
  69.     }
  70.  
  71.     offset=window->WScreen->Font->ta_YSize+3;
  72.     menu=firstmenu;
  73.     while (menu) {
  74.         if (xpos==0) xpos=menu->LeftEdge;
  75.         else menu->LeftEdge=xpos;
  76.         menu->Width=
  77.             TextLength(&window->WScreen->RastPort,menu->MenuName,strlen(menu->MenuName))+
  78.             window->WScreen->RastPort.Font->tf_XSize;
  79.         xpos+=menu->Width+16;
  80.  
  81.         y=0;
  82.         iwidth=0;
  83.         item=menu->FirstItem;
  84.  
  85.         while (item) {
  86.             item->TopEdge=y;
  87.  
  88.             if (item->Flags&ITEMTEXT) {
  89.                 struct IntuiText *text;
  90.                 int wid,mwidth=0,first=0;
  91.  
  92.                 item->Height=offset-1;
  93.  
  94.                 text=(struct IntuiText *)item->ItemFill;
  95.                 while (text) {
  96.                     text->FrontPen=fpen;
  97.                     text->BackPen=bpen;
  98.  
  99.                     if (first==0) {
  100.                         if (strncmp(text->IText,"   ",3)==0) text->IText=&text->IText[3];
  101.                         if (item->Flags&CHECKIT) text->LeftEdge=checkwidth;
  102.                         else text->LeftEdge=0;
  103.                     }
  104.  
  105.                     if (text->ITextFont) testtext.ITextFont=text->ITextFont;
  106.                     else testtext.ITextFont=&testattr;
  107.                     testtext.IText=text->IText;
  108.  
  109.                     wid=text->LeftEdge+IntuiTextLength(&testtext)+window->WScreen->RastPort.Font->tf_XSize;
  110.                     if (wid>mwidth) mwidth=wid;
  111.  
  112.                     if (text=text->NextText) {
  113.                         y+=offset;
  114.                         text->TopEdge=offset+3;
  115.                     }
  116.                     ++first;
  117.                 }
  118.                 if (item->Flags&COMMSEQ)
  119.                     mwidth+=comwidth+TextLength(&window->WScreen->RastPort,&item->Command,1);
  120.                 if (mwidth>iwidth) iwidth=mwidth;
  121.  
  122.                 y+=offset;
  123.             }
  124.             else {
  125.                 struct Image *image;
  126.                 int wid;
  127.  
  128.                 ++item->TopEdge;
  129.  
  130.                 image=(struct Image *)item->ItemFill;
  131.                 while (image) {
  132.                     if (image->ImageData==NULL) {
  133.                         image->Height=2;
  134.                         image->PlaneOnOff=fpen;
  135.                     }
  136.                     else {
  137.                         wid=image->LeftEdge+image->Width;
  138.                         if (wid>iwidth) iwidth=wid;
  139.                     }
  140.  
  141.                     y+=image->TopEdge+image->Height;
  142.  
  143.                     image=image->NextImage;
  144.                 }
  145.                 y+=3;
  146.             }
  147.             item=item->NextItem;
  148.         }
  149.  
  150.         item=menu->FirstItem;
  151.         while (item) {
  152.             item->Width=iwidth;
  153.             if (!(item->Flags&ITEMTEXT)) {
  154.                 struct Image *image;
  155.  
  156.                 image=(struct Image *)item->ItemFill;
  157.                 while (image) {
  158.                     if (image->ImageData==NULL) image->Width=iwidth;
  159.                     image=image->NextImage;
  160.                 }
  161.             }
  162.             item=item->NextItem;
  163.         }
  164.  
  165.         menu=menu->NextMenu;
  166.     }
  167.  
  168.     return((int)SetMenuStrip(window,firstmenu));
  169. }
  170.